# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.

# CMake lowest version requirement
cmake_minimum_required(VERSION 3.14)

# 设置工程名
project(ACLNN_ADDCUSTOM)

# Compile options
add_compile_options(-std=c++17)

# 设置编译选项
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  "./bin")    
set(CMAKE_CXX_FLAGS_DEBUG "-fPIC -O0 -g -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -O2 -Wall")

# 设置可执行文件名（如opapi_test），并指定待运行算子文件*.cpp所在目录
add_library(op SHARED op.cpp) 

# 设置ASCEND_PATH（CANN包目录）和INCLUDE_BASE_DIR（头文件目录）
if(NOT "$ENV{ASCEND_CUSTOM_PATH}" STREQUAL "")      
    set(ASCEND_PATH $ENV{ASCEND_CUSTOM_PATH})
else()
    set(ASCEND_PATH "/usr/local/Ascend/ascend-toolkit/latest")
endif()
message("ASCEND_PATH=${ASCEND_PATH}")
set(INCLUDE_BASE_DIR "${ASCEND_PATH}/include")
message("INCLUDE_BASE_DIR=${INCLUDE_BASE_DIR}")
include_directories(
    ${INCLUDE_BASE_DIR}
    ${INCLUDE_BASE_DIR}/aclnn
    ${ASCEND_PATH}/opp/vendors/customize/op_api/include
    ${CMAKE_SOURCE_DIR}/../utils
)

# 设置链接的库文件路径
target_link_libraries(
    op PRIVATE
    ${ASCEND_PATH}/lib64/libascendcl.so
    ${ASCEND_PATH}/opp/vendors/customize/op_api/lib/libcust_opapi.so
)

# 可执行文件在CMakeLists文件所在目录的bin目录下
install(TARGETS op DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})